from django.utils import timezone

from django.db import models


# Create your models here.

# 活动表


class ActivityInfo(models.Model):
    status_choices = (
        ('0', '待审核'),
        ('1', '不可发布'),
        ('2', '报名中'),
        ('3', '活动中'),
        ('4', '已结束'),
        ('5', '已删除'),
    )
    activity_status = models.CharField(verbose_name='活动状态', max_length=1, choices=status_choices, default='0')
    activity_name = models.CharField(verbose_name='活动名称', max_length=50, default=f'{timezone.now()} + 未命名活动',
                                     db_index=True)
    activity_initiator = models.ForeignKey('user.UserInfo', verbose_name='发起者', related_name='initiator_id',
                                           on_delete=models.SET_NULL, null=True, db_index=True)
    activity_initiator_phone = models.CharField(verbose_name='发起者联系方式', max_length=11, default='')
    activity_people_max_num = models.IntegerField(verbose_name='活动人数')
    activity_participator_num = models.IntegerField(verbose_name='参与人数', default=0)
    activity_collected_num = models.IntegerField(verbose_name='收藏人数', default=0)
    activity_province = models.CharField(verbose_name='省份', max_length=10, default='陕西省')
    activity_city = models.CharField(verbose_name='市区', max_length=10, default='西安市')
    activity_district = models.CharField(verbose_name='分区', max_length=10, default='雁塔区')
    activity_address = models.CharField(verbose_name='详细地址', max_length=50, default='西安理工大学金花家属楼')
    activity_begin_time = models.DateTimeField(verbose_name='开始时间', default=timezone.now)
    activity_end_time = models.DateTimeField(verbose_name='结束时间', default=timezone.now)
    activity_tag = models.CharField(verbose_name='活动标签', max_length=30, default='')
    activity_detail = models.TextField(verbose_name='活动详情', max_length=300, default='一个志愿活动')
    activity_cover = models.FileField(verbose_name='活动封面', upload_to='activityCover', default='')
    activity_create_time = models.DateTimeField(verbose_name='创建时间', default=timezone.now)
    activity_score = models.DecimalField(verbose_name='活动评分', max_digits=5, decimal_places=2, default=100.00)

    class Meta:
        db_table = 'activityinfo'
        verbose_name = "活动表"
        verbose_name_plural = verbose_name

    def __str__(self):
        """将模型类以字符串的方式输出"""
        return self.activity_name


class CommentInfo(models.Model):
    score = models.IntegerField(verbose_name='对活动打分', default=60)
    comment_text = models.TextField(verbose_name='评论内容', max_length=300, default='')
    comment_like = models.IntegerField(verbose_name='赞数量', default=0)
    comment_sender_nickname = models.CharField(verbose_name='评论者昵称', max_length=50, default='可爱的志愿者')
    comment_sender_avatar = models.CharField(verbose_name='评论者头像', max_length=150, default='')
    comment_activity = models.ManyToManyField('activity.ActivityInfo', verbose_name='所属活动',
                                              related_name='activity_comment_id', blank=True, db_index=True)
    comment_comment = models.ManyToManyField('activity.CommentInfo', verbose_name='子评论',
                                             related_name='comment_comment_id', blank=True, db_index=True)
    comment_create_time = models.DateTimeField(verbose_name='创建时间', default=timezone.now)

    class Meta:
        db_table = 'commentinfo'
        verbose_name = "评论表"
        verbose_name_plural = verbose_name
